﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>layui在线调试</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    @*<style>
        body {
        margin: 10px;
        }

        .demo-carousel {
        height: 200px;
        line-height: 200px;
        text-align: center;
        }

        .layui-table-tool-self {
        display: none;
        }
        </style>*@
</head>
<body>

    <table class="layui-hide" id="demo" lay-filter="test"></table>

    <script type="text/html" id="barDemo">
        {{# if(d.condition=='未发货'){}}
        <a class="layui-btn layui-btn-xs" lay-event="deliver">发货</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">在线追踪</a>
        {{# } else if(d.condition=='运输中') { }}
        <a class="layui-btn layui-btn-xs" lay-event="sign">签收</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">在线追踪</a>
        {{# } else if(d.condition=='已完成') { }}
        @*<a class="layui-btn layui-btn-xs" lay-event="receipt">回单</a>*@
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">在线追踪</a>
        {{# } else { }}
        <a class=" layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">在线追踪</a>
        {{# } }}
        @*<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">在线追踪</a>*@
        @*<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>*@
        @*<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>*@
    </script>

    <script src="~/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
    <script>
        //layui.config({
        //    version: '1606182314890' //为了更新 js 缓存，可忽略
        //});

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格

            //执行一个 table 实例
            table.render({
                elem: '#demo'
                , url: '/CargoownerTrack/GetList' //数据接口
                , title: '货主合同跟踪管理'
                , page: true //开启分页
                //, toolbar: 'default' //开启头工具栏，此处显示默认图标，可以自定义模板，详见文档
                , limit: 3
                , limits: [3, 6, 9, 12]
                , cols: [[ //表头
                    { type: 'checkbox', fixed: 'left' }//锁定第一列
                    //, { field: 'id', width: 102, title: '编号', sort: true }
                    , { field: 'numberId', width: 102, title: '合同编号', sort: true }
                    , { field: 'contractTitle', width: 120, title: '合同标题' }
                    , { field: 'fName', width: 180, title: '外协单位' }
                    , { field: 'oName', width: 110, title: '外协负责人' }
                    , { field: 'lName', title: '线路名称', width: 100 }
                    //, { field: 'freightrate', width: 100, title: '吨运价'}
                    //, { field: 'charterConditions', width: 100, title: '包车条件吨位' }
                    , { field: 'charterAmount', width: 100, title: '包车金额' }
                    , { field: 'signingDate', title: '签订日期', width: 145,templet: "<div>{{layui.util.toDateString(d.setTime, 'yyyy-MM-dd HH:mm')}}</div>"}
                    , { field: 'handler', width: 120, title: '经办人' }
                    //, { field: 'createTimedate', width: 145, title: '创建时间',templet: "<div>{{layui.util.toDateString(d.setTime, 'yyyy-MM-dd HH:mm')}}</div>" }
                    ,{
                        field: 'abnormal', title: '异常报警', width: 120,  templet: function (d) {
                            if(d.abnormal == 1)
                            {
                                return "正常";
                            }else if(d.abnormal == 2)
                            {
                                return "异常";
                            }
                            else{
                                return "--";
                            }
                        }
                    }
                    , { field: 'condition', width: 120, title: '货运状态',templet: function (d) {
                            if(d.condition == null)
                            {
                                return "--";
                            }
                            else{
                                return d.condition;
                            }
                        } }
                    , { fixed: 'right', width: 200, align: 'center',title: '操作', toolbar: '#barDemo' }
                ]]
            });

            //监听行工具事件
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'detail') {
                    //layer.msg('查看操作');
                    location.href="/CargoownerTrack/TrackLine?Id="+data.line;
                } else if (layEvent === 'delete') {
                    layer.msg(data.id);
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url:"/CargoownerTrack/DeleteCarfoownertrackbyId?id="+data.id,
                            type:"get",
                            dataType:"json",
                            success:function(obj){
                                if(obj>0){
                                    layer.msg('删除成功');
                                }
                            }
                        })
                        obj.del(); //删除对应行（tr）的DOM结构
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                }else if(layEvent=="deliver")
                {
                    layer.confirm('确认要发货吗？', function (index){
                        //layer.msg('发货成功');
                        $.ajax({
                            url:"/CargoownerTrack/Update?id="+data.id+"&Conditions=1",
                            type:"get",
                            dataType:"json",
                            success:function(obj){
                                if(obj>0){
                                    layer.msg('发货成功');
                                    location.reload();
                                }
                            }
                        })

                    })
                }else if(layEvent=="sign")
                {
                    layer.confirm('确认要签收吗？', function (index){
                        $.ajax({
                            url:"/CargoownerTrack/Update?id="+data.id+"&Conditions=2",
                            type:"get",
                            dataType:"json",
                            success:function(obj){
                                if(obj>0){
                                    layer.msg('签收成功');
                                    location.reload();
                                }
                            }
                        })
                        //layer.msg('签收成功');
                    })
                }

            });
        });
    </script>
</body>
</html>

